<template>
	<el-tooltip class="item" effect="dark" content="刷新" placement="top">
	  <el-button circle icon="Refresh" @click="update" />
	</el-tooltip>
  <el-table
    @selection-change="selectChange"
    :data="ScoreRuleList"
    style="width: 90%;border-radius: 8px; margin: 20px auto;box-shadow: 5px 5px 10px rgba(64, 158, 255, 0.5);"
    size="large"
    :header-cell-style="{
      background: '#337ecc !important',
      color: '#ffffff',
      border: 'none !important',
      textAlign: 'center',
    }"
    :cell-style="{ textAlign: 'center' }"
  >
    <el-table-column prop="empName" label="员工姓名" width="150">
      <template #default="scope">
        <el-tooltip content="详情" placement="top-start" effect="light">
          <a style="text-decoration: none; color: black">
            {{ scope.row.empName }}
          </a>
        </el-tooltip>
      </template>
    </el-table-column>
    <el-table-column prop="position" label="岗位"></el-table-column>
    <el-table-column label="收到任务时间" width="220">
      <template #default="scope">
        <div style="display: flex; align-items: center">
          <el-icon><timer /></el-icon>
          <span style="margin-left: 10px">{{ scope.row.startTime }}</span>
        </div>
      </template>
    </el-table-column>
    <el-table-column label="完成任务时间" width="220">
      <template #default="scope">
        <div style="display: flex; align-items: center">
          <el-icon><timer /></el-icon>
          <span style="margin-left: 10px">{{ scope.row.endTime }}</span>
        </div>
      </template>
    </el-table-column>
  </el-table>
  <pagination
    class="pagination"
    v-show="ScoreListPage.total > 0"
    :total="ScoreListPage.total"
    v-model:page="searchForm.page"
    v-model:limit="ScoreListPage.size"
    @pagination="handlePagination"
  />
</template>


<script setup>
import { ref, onMounted, onBeforeMount, reactive } from "vue";
import { Timer } from "@element-plus/icons-vue";
import { useRouter } from "vue-router";
import { getHistoryTaskPage} from "@/api/historyTask";
import { ElMessage } from 'element-plus'

const searchForm = ref({
  assessorId: JSON.parse(localStorage.getItem("userInfo")).id,
  type:"wage_emp",
  page: 1,
  page_size: 10,
});
const ScoreListPage = ref([]);
const ScoreRuleList = ref([]);
let empId = JSON.parse(localStorage.getItem("userInfo")).id;
onBeforeMount(() => {
  getHistoryTaskPage(searchForm.value).then((data) => {
    ScoreListPage.value = data.data;
    ScoreRuleList.value = data.data.records;
  });
});

const handlePagination=(value)=>{
    searchForm.value.page=value.page;
    searchForm.value.page_size=value.page_size
    getHistoryTaskPage(searchForm.value).then((data) => {
    ScoreListPage.value = data.data;
    ScoreRuleList.value = data.data.records;
  });
}

const update = () => {
    searchForm.value.page=1;
    searchForm.value.page_size=10
    getHistoryTaskPage(searchForm.value).then((data) => {
        if (data.code == 200) {
      ElMessage({
        message: "更新成功",
        type: "success",
      });
      ScoreListPage.value = data.data;
        ScoreRuleList.value = data.data.records;
    } 
    else {
      ElMessage.error("更新失败");
    }
  });
};
</script>

<style lang="scss" scoped>

</style>
